import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SPetUpdate } from "../../../../Message/Game/SPetUpdate";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SoundManager } from "../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../common/sound/SoundTypeConst";
//class PetBagUpdateCommand
    
    export  class PetBagUpdateCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var mb: MessageBlock;
            var sPetUpdate: SPetUpdate;
            var battlePet: SPetInfo;
            var callFun: Function;

            var loc1;
            sPetUpdate = null;
            callFun = null;
            mb = arg1;
            callFun = (): void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetBagUpdate, sPetUpdate));
                return;
            }
            super.call(mb);
            sPetUpdate = mb.messageBase as SPetUpdate;
            battlePet = _cache.pet.battlePet;
            if (battlePet) 
            {
                if (sPetUpdate.petInfo.uid == battlePet.uid) 
                {
                    if (sPetUpdate.petInfo.level > battlePet.level) 
                    {
                        SoundManager.instance.soundPlay(SoundTypeConst.PetUpdate);
                    }
                }
            }
            _cache.pet.petUpdate = sPetUpdate;
            flash.utils.setTimeout(callFun, 500);
            return;
        }
    }
